package Modele;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Observable;

public class Carte extends Observable {

	private Case[][] tabCases;
	private int width;
	private int height;
	private int num;
	
	public Carte(int w, int h, String carte, int n) {
		this.height = h;
		this.width = w;
		this.num = n;
		tabCases = new Case[w][h];
		for (int i = 0 ; i < w ; i ++) {
			for (int j = 0 ; j < h ; j ++) {
				tabCases[i][j] = new Case(0);
			}
		}
		CreerCarte(carte);
	}
	
	public Case[][] getTabCases() {
		return this.tabCases;
	}
	
	public int getW() {
		return this.width;
	}
	
	public int getH() {
		return this.height;
	}
	
	public int getNum() {
		return this.num;
	}
	
	public void CreerCarte(String carte) {
		String s = "";
		int i;
		int ligne = 0;
		int colonne = 0;
		try {
			BufferedReader br = new BufferedReader(new FileReader(carte));
			while ((s = br.readLine()) != null) {
				String[] sCase = s.split(" "); 
				for (i = 0 ; i < sCase.length ; i ++) {
					this.tabCases[ligne][colonne] = new Case(Integer.parseInt(sCase[i]));
					colonne ++;
				}
				colonne = 0;
				ligne ++;
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
